//
//  XSBigPictureBrowserCollectionViewCell.m
//  AudioVideo
//
//  Created by xueshan1 on 2019/10/12.
//  Copyright © 2019 xueshan1. All rights reserved.
//

#import "XSBigPictureBrowserCollectionViewCell.h"
@interface XSBigPictureBrowserCollectionViewCell ()

@property (nonatomic, copy) NSString *identifier;
@property (nonatomic, assign) PHImageRequestID imageRequestID;

@end

@implementation XSBigPictureBrowserCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
}

- (void)setPhotoModel:(XSPhotoModel *)photoModel{
    _photoModel = photoModel;
  
    if (photoModel.type == XSAssetMediaTypeVideo) {
        self.playBtn.hidden = NO;
    }else{
        self.playBtn.hidden = YES;
    }
    
    self.identifier = photoModel.asset.localIdentifier;
    self.imageV.image = nil;
    self.imageRequestID =[XSPhotosManager requestImageForAsset:photoModel.asset size:self.imageV.bounds.size progressHandler:nil completion:^(UIImage *image, NSDictionary *info) {
        
        if ([self.identifier isEqualToString:photoModel.asset.localIdentifier]) {
            self.imageV.image = image;
        }
        
        if (![[info objectForKey:PHImageResultIsDegradedKey] boolValue]) {
            self.imageRequestID = -1;
        }
    }];
    
}

- (IBAction)playBtnAction:(id)sender {
    
    if (self.playBtnBlack) {
        self.playBtnBlack(self.photoModel);
    }
}



@end
